<html>
<head><meta charset="utf-8"><title>removing unevaluated dead constants as defined per nll · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html">removing unevaluated dead constants as defined per nll</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193105074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105074">(Apr 06 2020 at 21:35)</a>:</h4>
<p>I've talked with <span class="user-mention" data-user-id="124288">@oli</span> some days ago and now with <span class="user-mention" data-user-id="116009">@nikomatsakis</span> about removing unevaluated dead constants as defined per nll</p>



<a name="193105085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105085">(Apr 06 2020 at 21:35)</a>:</h4>
<p>I was wondering how to do so</p>



<a name="193105125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105125">(Apr 06 2020 at 21:35)</a>:</h4>
<p>Right so what I was saying is that:</p>
<ul>
<li>when borrowck runs, there is already some notion of "live code" (whatever is reachable from MIR start)</li>
</ul>



<a name="193105133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105133">(Apr 06 2020 at 21:35)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="119009">@eddyb</span></p>



<a name="193105144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105144">(Apr 06 2020 at 21:35)</a>:</h4>
<p>and the rough idea here is that we want to find the constants reachable from that code and report errors that occur in their definitions</p>



<a name="193105154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105154">(Apr 06 2020 at 21:35)</a>:</h4>
<p>even if we might find <em>later</em> that some of that code is dead</p>



<a name="193105202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105202">(Apr 06 2020 at 21:36)</a>:</h4>
<p>(e.g., because of <code>if false { ... }</code>)</p>



<a name="193105230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105230">(Apr 06 2020 at 21:36)</a>:</h4>
<p>at least that is my memory</p>



<a name="193105247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105247">(Apr 06 2020 at 21:36)</a>:</h4>
<p>but what I don't remember quite is how/when the constant error reporting actually happens</p>



<a name="193105258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105258">(Apr 06 2020 at 21:36)</a>:</h4>
<p>wouldn't keeping all the constants outside of the basic blocks let them be removed freely from inside basic blocks?</p>



<a name="193105264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105264">(Apr 06 2020 at 21:36)</a>:</h4>
<p>btw this is about <a href="https://github.com/rust-lang/rust/issues/67191" title="https://github.com/rust-lang/rust/issues/67191">#67191</a></p>



<a name="193105322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105322">(Apr 06 2020 at 21:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105258" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105258">said</a>:</p>
<blockquote>
<p>wouldn't keeping all the constants outside of the basic blocks let them be removed freely from inside basic blocks?</p>
</blockquote>
<p>but we want to remove the ones from this new vector I was adding</p>



<a name="193105354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105354">(Apr 06 2020 at 21:37)</a>:</h4>
<p>so we do not error on <code>return something; refer_to_constant</code></p>



<a name="193105404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105404">(Apr 06 2020 at 21:38)</a>:</h4>
<p>but don't we want to error on that?</p>



<a name="193105408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105408">(Apr 06 2020 at 21:38)</a>:</h4>
<p>I'm slightly confused :)</p>



<a name="193105442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105442">(Apr 06 2020 at 21:38)</a>:</h4>
<p>to be honest at some point I was talking with <span class="user-mention" data-user-id="126931">@centril</span> about this and I do not understand</p>



<a name="193105455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105455">(Apr 06 2020 at 21:38)</a>:</h4>
<p>but read somewhere that this was defined on a lang meeting</p>



<a name="193105498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105498">(Apr 06 2020 at 21:39)</a>:</h4>
<p>I don't understand why doing more work to report less errors is better but I guess consistency is what was considered more important</p>



<a name="193105511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105511">(Apr 06 2020 at 21:39)</a>:</h4>
<p>if we want to keep only some consts, collect them just after the post-NLL simplifycfg or w/e</p>



<a name="193105546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105546">(Apr 06 2020 at 21:39)</a>:</h4>
<p>before any optimizations that could remove consts in non-dead code</p>



<a name="193105686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105686">(Apr 06 2020 at 21:41)</a>:</h4>
<p>I think that is roughly what we want to do -- but I'm not 100% sure what you mean by "collect" in that sentence</p>



<a name="193105822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105822">(Apr 06 2020 at 21:42)</a>:</h4>
<p>gather them into the separate <code>Vec&lt;ty::Const&gt;</code> that <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> wants to add</p>



<a name="193105933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105933">(Apr 06 2020 at 21:43)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> also told me</p>
<div class="codehilite"><pre><span></span>I guess we could make NLL fill in that array
but I don&#39;t like it
I&#39;d rather do a post-NLL optimization pass that removes all things NLL decided are unreachable
(which... should be very easy, because it simply is everything that still exists at that point)
so DCE after NLL would also clean up those constants
</pre></div>



<a name="193105948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105948">(Apr 06 2020 at 21:43)</a>:</h4>
<p>yeah I just don't 100% know where that vector 'lives' -- anyway I'm basically asking questions that are quite ignorant from not skimming the code.</p>



<a name="193105973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193105973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193105973">(Apr 06 2020 at 21:43)</a>:</h4>
<p>in my imagination there is some pass that walks the MIR and tries to evaluate constants it finds and reports errors</p>



<a name="193106023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106023">(Apr 06 2020 at 21:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105948" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105948">said</a>:</p>
<blockquote>
<p>yeah I just don't 100% know where that vector 'lives' -- anyway I'm basically asking questions that are quite ignorant from not skimming the code.</p>
</blockquote>
<p>the vector lives in mir body</p>



<a name="193106088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106088">(Apr 06 2020 at 21:44)</a>:</h4>
<p>I see, and we later iterate over this vector?</p>



<a name="193106100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106100">(Apr 06 2020 at 21:44)</a>:</h4>
<p>yeah in codegen</p>



<a name="193106103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106103">(Apr 06 2020 at 21:44)</a>:</h4>
<p>yes</p>



<a name="193106146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106146">(Apr 06 2020 at 21:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105973" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105973">said</a>:</p>
<blockquote>
<p>in my imagination there is some pass that walks the MIR and tries to evaluate constants it finds and reports errors</p>
</blockquote>
<p>the problem with this is that before this new PR, that happened but only with live constants not with the ones unreachable</p>



<a name="193106153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106153">(Apr 06 2020 at 21:44)</a>:</h4>
<p>then yes this seems roughly right. I guess the fact that we have an <code>&amp;mut Body</code> means we can basically either remove things from the vector or have it be empty and just populate it at the right time?</p>



<a name="193106173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106173">(Apr 06 2020 at 21:45)</a>:</h4>
<p>and we want to check the ones that are not reachable to report errors</p>



<a name="193106219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106219">(Apr 06 2020 at 21:45)</a>:</h4>
<p>well I <em>think</em> the idea was to report errors for live constants, but we just have to be sure which definition of "live" we want to use</p>



<a name="193106258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106258">(Apr 06 2020 at 21:45)</a>:</h4>
<p>ohh right, I didn't mean live in the nll sense of live :)</p>



<a name="193106309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106309">(Apr 06 2020 at 21:46)</a>:</h4>
<p>i.e., if we just walk the set of blocks reachable from the start block (at the time of borrow check, before doing any optimizations), then it's any constants referenced from within those blocks?</p>



<a name="193106319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106319">(Apr 06 2020 at 21:46)</a>:</h4>
<p>I meant stuff that is reachable and wasn't optimized away</p>



<a name="193106352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106352">(Apr 06 2020 at 21:46)</a>:</h4>
<p>alternatively, if we run DCE (which we maybe even already do, I can't remember) before doing any other optimizations, then it's just "all blocks"</p>



<a name="193106514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106514">(Apr 06 2020 at 21:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193106153" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193106153">said</a>:</p>
<blockquote>
<p>then yes this seems roughly right. I guess the fact that we have an <code>&amp;mut Body</code> means we can basically either remove things from the vector or have it be empty and just populate it at the right time?</p>
</blockquote>
<p>sorry, didn't get what's roughly right?</p>



<a name="193106598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106598">(Apr 06 2020 at 21:48)</a>:</h4>
<p>what <span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105511" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193105511">wrote here</a>:</p>
<blockquote>
<p>if we want to keep only some consts, collect them just after the post-NLL simplifycfg or w/e</p>
</blockquote>



<a name="193106727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193106727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193106727">(Apr 06 2020 at 21:50)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="193107233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193107233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193107233">(Apr 06 2020 at 21:55)</a>:</h4>
<p>you don't even need simplifycfg if you use an RPO traversal :P</p>



<a name="193107321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193107321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193107321">(Apr 06 2020 at 21:56)</a>:</h4>
<p>actually do we have a cheaper <code>VecDeque</code>+<code>BitSet</code> traversal that doesn't preserve dominator ordering?</p>



<a name="193107344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193107344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193107344">(Apr 06 2020 at 21:56)</a>:</h4>
<p>but still only visits reachable blocks?</p>



<a name="193153438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193153438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193153438">(Apr 07 2020 at 08:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193106100" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193106100">said</a>:</p>
<blockquote>
<p>yeah in codegen</p>
</blockquote>
<p>That's what <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span>'s PR does atm. I don't understand how that is correct. What if codegen never runs...? Then, AIUI you wouldn't get any error.</p>



<a name="193153627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193153627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193153627">(Apr 07 2020 at 08:18)</a>:</h4>
<p>It's important that errors happen in the <em>analysis</em> "phase" of the compiler. Whether or not MIR optimizations are run or codegen is run shouldn't affect this</p>



<a name="193159339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193159339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193159339">(Apr 07 2020 at 09:18)</a>:</h4>
<p>we still need to run it during codegen because some error are only triggered after monomorphization since <code>TooGeneric</code> errors are silent</p>



<a name="193159344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193159344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193159344">(Apr 07 2020 at 09:18)</a>:</h4>
<p>so we need both</p>



<a name="193162130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162130">(Apr 07 2020 at 09:45)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> this change doesn't move anything, it just makes it easier to be correct in the future wrt not losing track of consts</p>



<a name="193162179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162179">(Apr 07 2020 at 09:46)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  sure</p>



<a name="193162271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162271">(Apr 07 2020 at 09:47)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  Me and <span class="user-mention" data-user-id="124288">@oli</span> were discussing privately re. doing it in <code>run_optimization_passes</code> vs. having some RPO traversal in analysis</p>



<a name="193162322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162322">(Apr 07 2020 at 09:47)</a>:</h4>
<p>I feel that doing it in <code>run_optimization_passes</code> is fragile as it relies on e.g., <code>SimplifyCfg</code> and other passes not declaring too much code dead and whatnot</p>



<a name="193162343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162343">(Apr 07 2020 at 09:47)</a>:</h4>
<p>Fragile as in "stability hazard"</p>



<a name="193162484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162484">(Apr 07 2020 at 09:49)</a>:</h4>
<p>you don't need RPO, RPO is for a specific order which preserves dominance (very important to SSA-like stuff)</p>



<a name="193162507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162507">(Apr 07 2020 at 09:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193107321" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll/near/193107321">said</a>:</p>
<blockquote>
<p>actually do we have a cheaper <code>VecDeque</code>+<code>BitSet</code> traversal that doesn't preserve dominator ordering?</p>
</blockquote>
<p>^^ see this</p>



<a name="193162537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162537">(Apr 07 2020 at 09:49)</a>:</h4>
<p>you just need "visit all reachable blocks"</p>



<a name="193162614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162614">(Apr 07 2020 at 09:50)</a>:</h4>
<p>and yeah I favor something that can just run immediately after NLL and doesn't depend on whatever SimplifyCfg might do</p>



<a name="193162652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162652">(Apr 07 2020 at 09:50)</a>:</h4>
<p>like <code>if false</code> should not be considered dead code. although. hmm</p>



<a name="193162660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193162660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193162660">(Apr 07 2020 at 09:50)</a>:</h4>
<p>why do we want to ignore constants in dead code anyway?</p>



<a name="193163016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163016">(Apr 07 2020 at 09:54)</a>:</h4>
<p>idk, lang team decided we want to</p>



<a name="193163301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163301">(Apr 07 2020 at 09:57)</a>:</h4>
<p>do we remove this dead code <em>before</em> NLL? does NLL just not walk it?</p>



<a name="193163317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163317">(Apr 07 2020 at 09:57)</a>:</h4>
<p>because we could do the gathering even earlier I suspect</p>



<a name="193163485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163485">(Apr 07 2020 at 09:59)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> consider e.g.:</p>
<div class="codehilite"><pre><span></span><span class="k">return</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// OK because its dead code</span>
</pre></div>



<a name="193163545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163545">(Apr 07 2020 at 09:59)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  Right; I basically also mean "visit all reachable blocks and collect their constants"</p>



<a name="193163610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163610">(Apr 07 2020 at 10:00)</a>:</h4>
<p>running immediately after NLL seems sensible</p>



<a name="193163649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163649">(Apr 07 2020 at 10:00)</a>:</h4>
<p>anyway yeah I agree with not relying on <code>SimplifyCfg</code></p>



<a name="193163872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163872">(Apr 07 2020 at 10:02)</a>:</h4>
<p>so... if we move the mir opt pass doing the collection all the way to the front of the optimization list and make it look for reachable constants manually, would that be better? or should we move this into the <code>mir_validated</code> query?</p>



<a name="193163891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163891">(Apr 07 2020 at 10:02)</a>:</h4>
<p>I'd say <code>mir_validated</code></p>



<a name="193163911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163911">(Apr 07 2020 at 10:03)</a>:</h4>
<p>ok</p>



<a name="193163924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20unevaluated%20dead%20constants%20as%20defined%20per%20nll/near/193163924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20unevaluated.20dead.20constants.20as.20defined.20per.20nll.html#193163924">(Apr 07 2020 at 10:03)</a>:</h4>
<p>just because it pertains to that aspect</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>